<!DOCTYPE html>
<html>
<head>
    <head/>
    <title>科室详情</title>
    <titleType style="display: none;">ksDetail</titleType>
        <%- include('./_global/appendJs') %>
</head>
<style>
    .swiper-wrapper .swiper-slide{
        float: left;
    }
    .docSpecialty{
        height: 24px;
    }
    .remove-header{
        top:0!important;
    }
    .doctor-detail .check-date-box .swiper-slide{
        width: calc(14.2% - 0.25rem);
    }
    .numInfo {
        width: calc(100% - 4.9rem - 60%);
        float: right;
        height: auto;
        text-align: center;
    }
    .numInfo span{
            bottom: 0.2rem;
        position: absolute;
        text-align: center;
    }
</style>


<body>
<section class="page-wrap office-box">
    <header class="header-box grey fixed">
        <div class="header-content">
            <div class="left-tool">
                <a class="back" href="javascript:void(0);"><i class="iconfont icon-back"></i></a>
            </div>
            <div class="title">科室详情</div>
        </div>
    </header>
   <!--  <section class="page-wrap hospital-detail">
        <div class="hospital-tab-box">
            <ul class="row" id="ListTab">
                <li class="col-xs-6 active"  index="0">
                    <a>按专家预约</a>
                </li>
                <li class="col-xs-6"   index="1">
                    <a>按日期预约</a>
                </li>
            </ul>
        </div>
    </section> -->
     <div id="ListTabBox">
    <div class="office-list-box tab active" index="0" id="docDiv">
        <ul id="docUl">
        </ul>
    </div>

    <div class="page-wrap doctor-detail tab" index='1' style="display: none">
       <div id="sliderTimer" class="check-date-box swiper-container swiper-container-horizontal swiper-container-free-mode">
        <div class="swiper-wrapper" style="transform: translate3d(0px, 0px, 0px);height:60px;" id="timeSchedule">
        </div> 
    </div>
    <div id="ListTabBox">
    <div class="office-list-box" index="0" id="docDiv">
     <ul id="datedocUl">
     </ul>
 </div>
</div>
    </div>
</div>
</section>
</body>
<script src="/static/lib/forweb.js"></script>
<script src="/quickJs/scripts/swiper/3.4.2/js/swiper.min.js"></script>
<script src="/static/js/<%=type%>/pageUrl.js"></script>
<script src="/static/js/<%=type%>/yygh.js"></script>
<script type="text/html" id="docyhLi">
    <li>
        <img class="docImgUrl" src="images/doctor4.png">
        <div class="text-box">
            <span class="blue-text docName">布朗</span>
            <span class="sub-text docTitle">副主任医师</span>
            <span class="docSpecialty"></span>
        </div>
        <div class="numInfo">
            <a class="blue-yy active" href="javascript:void(0);">预约</a>
            <!--<span class="fee"></span>-->
        </div>
        
    </li>
</script>
<!--<script type="text/html" id="docwhLi">-->
    <!--<li>-->
        <!--<img class="docImgUrl" src="">-->
        <!--<div class="text-box">-->
            <!--<span class="blue-text docName">布朗</span>-->
            <!--<span class="sub-text docTitle">副主任医师</span>-->
            <!--<span> </span>-->
            <!--<span> </span>-->
        <!--</div>-->
        <!--<a class="blue-yy" href="javascript:void(0);">约满</a>-->
    <!--</li>-->
<!--</script>-->
<script type="text/html" id="dateDiv">
    <div class="swiper-slide swiper-slide-active" >
        <div class="time-wrap">
            <p class="text-week">周日</p>
            <p class="text-time">2016-09-29</p>
        </div>
    </div>
</script>
<script type="text/html" id="noInfo">
    <li class="yysj">
        <div class="text-box" style="width: 100%;margin-left: 0;">
            <div class="docSpecialty" style="text-align: center;">暂无医生</div>
        </div>
    </li>
</script>
<script type="text/javascript">
    var docType='expert';

    function toYsDetail(ysInfo){
            var data = docType!="expert"?"selectTime="+docType:"";
            StoreCache.setCache("YYGH_YSINFO", JSON.parse(ysInfo));
            $.pageSwitch.goToUrl("myOrder", "docDetail", data);
    }

    var page_ksDetail = (function($, page_ksDetail) {

        var formatTime = "MM-dd";
        var showTime=false;
        function switchcCntent(event) {
//            var node = event.target.parentElement;

            if (!$(this).hasClass("active")) {
                $(this).addClass("active").siblings().removeClass("active");
            }
            var index = $(this).attr("index");
            $("#ListTabBox").find(".tab").hide();
            $("#ListTabBox").find(".tab[index='" + index + "']").show();
            if(index ==1){
                var dv =  $('#sliderTimer').find('.time-wrap')[0];
                $(dv).trigger("click");

            }
        };

        /**加载视图*/
        function initView(){
            /**移动端进入删除改变定位的top*/
            if(ServiceType == "mobile")
            {
                $(".filtrate-sub-check").addClass("remove-header");
            }

            if($.QuickVersion["isWeixin"]){
                $("#weixinSx").show();
            }


            /**ui脚本点击日期*/
            $("#sliderTimer").on("click",".time-wrap",function(){
                $(".yyrq").removeClass("active");
                $("#sliderTimer").find(".time-wrap").removeClass("active");
                $(this).addClass("active");
                $('#datedocUl')[0].innerHTML='';
                var yyrq='';
                $("#sliderTimer").find(".time-wrap").each(function(){
                    if($(this).hasClass("active")){
                        yyrq = $(this).attr("value");
                    }
                });
                docType =yyrq;
                page_ksDetail.initDocInfo(yyrq,'#datedocUl');

            });

            var swiper = new Swiper("#sliderTimer", {
                width:"100%",
                pagination: ".swiper-pagination",
                slidesPerView: 5,
                paginationClickable: true,
                spaceBetween: 0,
                freeMode: true
            });
            $(".sx-icon").data("obj", swiper);
            /**筛选按钮*/
            $(".sx-icon").click(function(){
                page_ksDetail.sxShowOrHide();
            });

            $(".sxxx").on("click", "li", function addlist() {
                $(this).toggleClass("active");
                var value = $(this).attr("value");
                /**号源类型*/
                if($(this).hasClass("hylx") && value != "0"){
                    $(".hylx[value='0']").removeClass("active");

                }
                /**号源类型*/
                if($(this).hasClass("yszc") && value != "0"){
                    $(".yszc[value='0']").removeClass("active");

                }
                /**预约时间*/
                if($(this).hasClass("yyrq")){
                    $("#sliderTimer").find(".time-wrap").removeClass("active");
                }

                /**加载医生信息*/
                page_ksDetail.initDocInfo();
            });


            /**号源类型*/
            $("#hylx").on("click",function(){
                $(this).parents("li").siblings().find(".filtrate-sub-check").hide();
                $("#hylxChildren").toggle();
            });

            $("#hylxChildren").on("click","li",function(){
                if(!$(this).hasClass("active")){
                    $(this).siblings("li").removeClass("active");
                    $(this).addClass("active");
                    $(this).parents(".filtrate-sub-check").hide();
                    var val = $(this).attr("value");
                    $(".sxxx").find(".hylx").removeClass("active");
                    $(".sxxx").find(".hylx[value='"+val+"']").addClass("active");
                    /**加载医生信息*/
                    page_ksDetail.initDocInfo();


                }
            })


            /**医生职称*/
            $("#yszc").on("click",function(){
                $(this).parents("li").siblings().find(".filtrate-sub-check").hide();
                $("#yszcChildren").toggle();
            });


            $("#yszcChildren").on("click","li",function(){
                if(!$(this).hasClass("active")){
                    $(this).siblings("li").removeClass("active");
                    $(this).addClass("active");
                    $(this).parents(".filtrate-sub-check").hide();
                    var val = $(this).attr("value");
                    $(".sxxx").find(".yszc").removeClass("active");
                    $(".sxxx").find(".yszc[value='"+val+"']").addClass("active");
                    /**加载医生信息*/
                    page_ksDetail.initDocInfo();


                }
            })


            /**预约时间*/
            $("#yysj").on("click",function(){
                $(this).parents("li").siblings().find(".filtrate-sub-check").hide();
                $("#yysjChildren").toggle();
            });

            $("#yysjChildren").on("click","li",function(){
                if(!$(this).hasClass("active")){
                    $(this).siblings("li").removeClass("active");
                    $(this).addClass("active");
                    $(this).parents(".filtrate-sub-check").hide();
                    var val = $(this).attr("value");
                    $("#sliderTimer").find(".time-wrap").removeClass("active");
                    $("#sliderTimer").find(" .time-wrap[value='"+val+"']").addClass("active");
                    /**加载医生信息*/
                    page_ksDetail.initDocInfo();
                }
            })

            $(".bg").click(function(){
                $(".filtrate-sub-check").hide();
            });
        }

        /**筛选显示*/
        function sxShowOrHide(){
            $(".sxxx").toggle();
            var swiper = $(".sx-icon").data("obj");
            swiper.onResize();
        }

        /**加载数据*/
        function initData(){
            /**注册方法jsbridge调用*/
            $.JkcsUtils.jsbridgeRegister("sxShowOrHide", page_ksDetail.sxShowOrHide);
            /**加载医生信息*/
            page_ksDetail.initDocInfo();
            /**加载预约日期*/
            page_ksDetail.setYyghDate();
        }

        /**加载医生信息*/
        function initDocInfo(selectedDate,domId){
            var params = {};

            /**获取预约日期*/
            var info = StoreCache.getCache("YYGH_KSINFO");
            var currDate = new Date();
            var startDate = currDate.DateAdd("d", 1);
            var endDate = currDate.DateAdd("d", 8);
            params ={
                hosCode:info["hosCode"],
                depCode: info["depCode"],
                startTime:startDate.Format("yyyy-MM-dd"),
                endTime:endDate.Format("yyyy-MM-dd"),
                oneDepCode:info["oneDepCode"]


            };
            var yyrq = "";
            if(selectedDate){
                params.startTime = selectedDate;
                params.endTime = selectedDate;
            }

            /**选中的预约时间*/
            if(!StringUtils.isEmpty(yyrq)){
                params["orderDate"] = yyrq;
            }

            /**获取科室信息*/

            /**设置title*/
            $(".title").text(info["depName"]);
                $(document).attr("title",info["depName"]);

            /**加载医生信息*/
            // params["hosCode"] = info["hosCode"];
            // params["depCode"] = info["depCode"];
            // params["parentCode"] = info["parentCode"];
            // params["pageNum"] = 1;
            // params["pageSize"] = 10;

            if(domId){
                $(domId)[0].innerHTML='';
            }else{
                $("#docUl").remove();
                var docUl = $("<ul>").attr({"id":"docUl"});
                $("#docDiv").append(docUl);
            }

            layui.use("flow", function(){
                var flow = layui.flow;
                flow.load({
                    elem:domId?domId: "#docUl" //指定列表容器
                    ,end: " "
                    ,done: function(page, next){ //到达临界点（默认滚动触发），触发下一页
                        $.QuickRemote.AjaxJson({
                            funcName:$.getMyorderUrl.getpageUrl("getResource")
                            ,callback:page_ksDetail.doctorListHandler
                            ,params:params
                            ,additionParams: {next: next}
                        });
                    }
                });
            });
        }


        function doctorListHandler(result, obj) {
            var lis = [];
            //顶部添加科室信息
            result["outpatient"].forEach(function(arr){
                var mzLi = "";
                mzLi = $($("#docyhLi").html());
                $(mzLi).find(".docImgUrl").attr("src","/static/images/icon_ptmz.png");
                $(mzLi).find(".docName").text(arr["deptName"]);
                $(mzLi).find(".docTitle").text("");
                $(mzLi).find(".docSpecialty").text("简介："+arr["resourceInfo"]);
                arr["orderType"] = "2";
                $(mzLi).find("a").attr("onclick","toYsDetail('"+JSON.stringify(arr)+"')");
                 lis.push($(mzLi).prop("outerHTML"));


            });
             var info = StoreCache.getCache("YYGH_KSINFO");
           

            result["doctors"].forEach(function(arr){
              
                var docLi = "";
                docLi = $($("#docyhLi").html());
//                if(item["scheduleDate"]){
//                    docLi = $($("#docyhLi").html());
//                }else{
//                    docLi = $($("#docwhLi").html());
//                }
                $(docLi).find(".docImgUrl").attr("src","/static/images/doctor_image.jpg");
                $(docLi).find(".docName").text(arr["docName"]);
                $(docLi).find(".docTitle").text(arr["regType"]);
                $(docLi).find(".docSpecialty").text("简介："+arr["docInfo"]);
//                var fee =  parseInt(item["visitCost"]).toFixed(2);
//                $(docLi).find(".fee").text("￥"+fee);
//                $(docLi).find(".docSpecialty").text(item["docSpecialty"]);
                arr["orderType"] = "1";
                $(docLi).find("a").attr("onclick","toYsDetail('"+JSON.stringify(arr)+"')");
                lis.push($(docLi).prop("outerHTML"));

            });
            /*if(JSON.stringify(result["data"])=="{}"){
                lis.push($("#noInfo").html());
            }*/
            obj.next(lis.join(''),false);
        }
        /**设置预约挂号日期 当前日期往后退7天*/


       
        function setYyghDate() {
            var currDate = new Date();
            var year1 = -1, year2 = -1;
            for(var i=1; i<=7; i++)
            {
                var date = currDate.DateAdd("d", i);
                year1 = date.getFullYear();
                if(year1 != year2 && year2 != -1 && !showTime){
                    showTime = true;
                    formatTime = "MM-dd";
                    $("#timeSchedule").empty();
                    page_ksDetail.setYyghDate();
                    break;
                }
                year2 = year1;
                var dateDiv = $($("#dateDiv").html());
                dateDiv.find(".text-week").html(date.getWeekDay());
                dateDiv.find(".text-time").html(date.Format(formatTime));
                dateDiv.find(".time-wrap").attr("value",date.Format("yyyy-MM-dd"));
                // dateDiv.appendTo($("#timeSchedule"));
                dateDiv.appendTo($("#timeSchedule"));
                var li = $("<li><a href='javascript:void(0);'></a></li>");
                $(li).attr("value", date.Format("MM-dd"));
                $(li).find("a").html(date.Format(formatTime)+" "+date.getWeekDay());
                $(li).appendTo($("#yysjUl"));
                if(i==1)
                {
                    dateDiv.trigger("click");
                }
            }
        }


        var cfg_def = {
            initData: initData,
            initView: initView,
            switchcCntent: switchcCntent,
            sxShowOrHide: sxShowOrHide,
            initDocInfo: initDocInfo,
            doctorListHandler: doctorListHandler,
            setYyghDate: setYyghDate,
        }

        page_ksDetail.init = function(cfg){
            $.extend(page_ksDetail, cfg_def, cfg);
            page_ksDetail.initData();
            page_ksDetail.initView();
           // $('#ListTab li').click(page_ksDetail.switchcCntent)
        }

        return page_ksDetail;
    })(jQuery, {});
    
</script>

</html>



